package gang.org.springframework.framework.metadata;

import java.lang.annotation.Annotation;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author gang.chen
 * @since  2021/6/30 8:23
 */
public class GangAnnotationAttributes extends LinkedHashMap<String,Object> {

    private final String displayName;
    private final Class<? extends Annotation> annotationType;

    public GangAnnotationAttributes(Class<? extends Annotation> annotationType){
        this.annotationType = annotationType;
        this.displayName = annotationType.getName();
    }

    public GangAnnotationAttributes(Map<String, Object> map){
        super(map);
        this.annotationType = null;
        this.displayName = "unknow";
    }

    public static GangAnnotationAttributes fromMap(Map<String, Object> map){
        if (map == null) {
            return null;
        }else {
            return map instanceof GangAnnotationAttributes ? (GangAnnotationAttributes) map : new GangAnnotationAttributes(map);
        }
    }

    public String[] getStringArray(String attributeName){

        return getRequiredAttribute(attributeName, String[].class);

    }

    public <T> T getRequiredAttribute(String attributeName, Class<T> expectedType){

        Object value = get(attributeName);

        return (T)value;
    }

    public boolean getBoolean(String attributeName){
        return getRequiredAttribute(attributeName, Boolean.class);
    }
}
